#include "vli.h"
#include "ecc.h"
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>

extern struct ecc_curve sm2_curve;

void bn_print(const u64* n, int num)
{
    for (int i = num - 1; i >= 0; i--) {
        printf("%08X ", (uint32_t)((n[i] >> 32) & 0xFFFFFFFF));
        printf("%08X ", (uint32_t)(n[i] & 0xFFFFFFFF));
    }
    printf("\n");
}

void __bn_prints(const u64* n, ...)
{
    u64* mode;
    va_list   v;
    bn_print(n, ECC_MAX_DIGITS);
    va_start(v, n);
    mode = va_arg(v, u64*);
    while (mode != NULL) {
        bn_print(mode, ECC_MAX_DIGITS);
        mode = va_arg(v, u64*);
    }
    va_end(v);
}

u64 k[ECC_MAX_DIGITS] = {0x6d54b80deac1bc21, 0xef3cc1fa3cdbe4ce, 0x16680f3ad9c02dcc, 0x59276e27d506861a};
u64 e[ECC_MAX_DIGITS] = {0xf4486fdfc0d28640, 0x17e6ab5a19ce7b31,0xace692ed534382eb, 0xf0b43e94ba45acca};
u64 dA[ECC_MAX_DIGITS] = {0x42fb81ef4df7c5b8, 0x889393692860b51a, 0x3f36e38ac6d39f95, 0x3945208f7b2144b1};

void vli_test()
{
    // ecc_point r;
    // ecc_point_mult(&sm2_curve, &r, &sm2_curve.g, k, NULL);
    // bn_prints(k, r.x, r.y);
    u64 r[2*ECC_MAX_DIGITS];
    u64 y1[ECC_MAX_DIGITS] = {0x02DF32E52139F0A0, 0xD0A9877CC62A4740,
        0x59BDCCE36B692135, 0xBC3762A2F4F6779C};
    vli_mod_square_fast(r, y1, sm2_curve.p, ECC_MAX_DIGITS);
    // vli_square(r, y1, ECC_MAX_DIGITS);
    bn_prints(r+ECC_MAX_DIGITS, r);
}